<?php
class filtersSelectorForm extends sfForm
{
  public function configure()
  {
    $this->users  = aluToolkit::useValueAsKey(LogPeer::getAllUsers());
    $machines     = aluToolkit::useValueAsKey(LogPeer::getAllMachines());

    $non = array('Non' => 'Non');
    $this->users = array_merge($non, $this->users);
    $machines    = array_merge($non, $machines);

    $grouper      = array('Non', 'Machine', 'Utilisateur');

    $date1 = new sfWidgetFormJQueryDate(array(
      'image'       => '/images/calendar.png',
      'culture'     => 'fr',
      'date_widget' => new sfWidgetFormDate(array('can_be_empty' => false)),
    ));

    $date2 = new sfWidgetFormJQueryDate(array(
      'image'       => '/images/calendar.png',
      'culture'     => 'fr',
      'date_widget' => new sfWidgetFormDate(array('can_be_empty' => false)),
    ));

    $types = $non;
    foreach (TypesPeer::doSelect(new Criteria()) as $type)
    {
      $types[$type->getId()] = $type->getLibelle();
    }

    $this->setWidgets(array(
      'periode' => new sfWidgetFormDateRange(array(
        'from_date' => $date1,
        'to_date'   => $date2,
        'template'  => 'du %from_date% au %to_date%',
      )),
      'machine' => new sfWidgetFormSelect(array('choices' => $machines)),
      'user'    => new sfWidgetFormSelect(array('choices' => $this->users)),
      'grouper' => new sfWidgetFormSelect(array('choices' => $grouper)),
      'type'    => new sfWidgetFormSelect(array('choices' => $types)),
    ));

    $this->setValidators(array(
      'periode' => new sfValidatorPass(),
      'machine' => new sfValidatorChoice(array('choices' => $machines)),
      'user'    => new sfValidatorChoice(array('choices' => $this->users)),
      'grouper' => new sfValidatorChoice(array('choices' => $grouper)),
    ));
    $this->getWidgetSchema()->setNameFormat('filtres[%s]');
  }
}